/*
 * App.java
 *
 * Created on Nov 4, 2011, 11:08:49 PM
 */
package bounce;

import java.awt.Dimension;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author PANAIMIN
 */
public class App extends javax.swing.JFrame {

    static final Logger _logger = Logger.getLogger("Bounce");

    public static App Instance() {
        if(_instance == null)
            _instance = new App();
        return _instance;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _stage = Stage.Instance();
        _menuBar = new javax.swing.JMenuBar();
        _fileMenu = new javax.swing.JMenu();
        _newGameMenu = new javax.swing.JMenuItem();
        _selectLevelMenu = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        _endlessBall = new javax.swing.JCheckBoxMenuItem();
        _separator1 = new javax.swing.JPopupMenu.Separator();
        _exitMenu = new javax.swing.JMenuItem();
        _helpMenu = new javax.swing.JMenu();
        _aboutMenu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Bounce");

        _stage.setPreferredSize(new java.awt.Dimension(900, 600));

        javax.swing.GroupLayout _stageLayout = new javax.swing.GroupLayout(_stage);
        _stage.setLayout(_stageLayout);
        _stageLayout.setHorizontalGroup(
            _stageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        _stageLayout.setVerticalGroup(
            _stageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 278, Short.MAX_VALUE)
        );

        _fileMenu.setText("File");

        _newGameMenu.setText("New game");
        _newGameMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _newGameMenuActionPerformed(evt);
            }
        });
        _fileMenu.add(_newGameMenu);

        _selectLevelMenu.setText("Select a level");
        _selectLevelMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _selectLevelMenuActionPerformed(evt);
            }
        });
        _fileMenu.add(_selectLevelMenu);
        _fileMenu.add(jSeparator1);

        _endlessBall.setSelected(true);
        _endlessBall.setText("Endless ball");
        _fileMenu.add(_endlessBall);
        _fileMenu.add(_separator1);

        _exitMenu.setText("Exit");
        _exitMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _exitMenuActionPerformed(evt);
            }
        });
        _fileMenu.add(_exitMenu);

        _menuBar.add(_fileMenu);

        _helpMenu.setText("Help");

        _aboutMenu.setText("About");
        _aboutMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _aboutMenuActionPerformed(evt);
            }
        });
        _helpMenu.add(_aboutMenu);

        _menuBar.add(_helpMenu);

        setJMenuBar(_menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(_stage, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(_stage, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _newGameMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__newGameMenuActionPerformed
        ((Stage)_stage).newGame(1);
    }//GEN-LAST:event__newGameMenuActionPerformed

    private void _selectLevelMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__selectLevelMenuActionPerformed
        LevelDialog dlg = new LevelDialog();
    }//GEN-LAST:event__selectLevelMenuActionPerformed

    private void _exitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__exitMenuActionPerformed
        System.exit(0);
    }//GEN-LAST:event__exitMenuActionPerformed

    private void _aboutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__aboutMenuActionPerformed
        AboutDialog dlg = new AboutDialog();
    }//GEN-LAST:event__aboutMenuActionPerformed

    public static void main(String[] args) {
        _logger.setLevel(Level.ALL);
        try {
            FileHandler fh = new FileHandler("%t/bounce.log");
            fh.setFormatter(new SimpleFormatter());
            _logger.addHandler(fh);
        }
        catch (IOException e) {}
        try {
            UIManager.setLookAndFeel(
                UIManager.getSystemLookAndFeelClassName());
        }
        catch (UnsupportedLookAndFeelException e) { }
        catch (ClassNotFoundException e) { }
        catch (InstantiationException e) { }
        catch (IllegalAccessException e) { }
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                App.Instance().setVisible(true);
            }
        });
    }

    private App() {
        initComponents();
        setLocation(100, 100);
        setSize(new Dimension(906, 650));
        setResizable(false);
        addKeyListener(Stage.Instance());
    }

    private static App  _instance = null;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem _aboutMenu;
    public javax.swing.JCheckBoxMenuItem _endlessBall;
    private javax.swing.JMenuItem _exitMenu;
    private javax.swing.JMenu _fileMenu;
    private javax.swing.JMenu _helpMenu;
    private javax.swing.JMenuBar _menuBar;
    private javax.swing.JMenuItem _newGameMenu;
    private javax.swing.JMenuItem _selectLevelMenu;
    private javax.swing.JPopupMenu.Separator _separator1;
    private javax.swing.JPanel _stage;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
